﻿/****************************** Module Header ******************************\
 * Module Name:  ScreenHelper.cs
 * Module Version:  1.0.0 (2013-7-2)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used for screen. 
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace UCL.Forms
{
    /// <summary>
    /// 屏幕助手类
    /// <para>2013-7-2 by sutroon</para>
    /// </summary>
    public class ScreenHelper
    {
        /// <summary>
        /// 获取屏幕图像
        /// <para>2013-7-2 by sutroon</para>
        /// </summary>
        /// <returns></returns>
        public static Bitmap GetScreenImage()
        {
            // 通过Graphics的CopyFromScreen方法把全屏图片的拷贝到我们定义好的一个和屏幕大小相同的空白图片中，
            // 拷贝完成之后，CatchBmp就是全屏图片的拷贝了，然后指定为截图窗体背景图片就好了。
            // 新建一个和屏幕大小相同的图片
            Bitmap bmp = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);

            // 创建一个画板，让我们可以在画板上画图
            // 这个画板也就是和屏幕大小一样大的图片
            // 我们可以通过Graphics这个类在这个空白图片上画图
            Graphics g = Graphics.FromImage(bmp);

            // 把屏幕图片拷贝到我们创建的空白图片 CatchBmp中
            g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
            return bmp;
        }

        public static Point GetScreenPoint(int w, int h, string direct="RIGHT_CENTER")
        {
            return new Point((Screen.PrimaryScreen.Bounds.Width - w), (Screen.PrimaryScreen.Bounds.Height - h)/2);
        }
    }
}
